version 16
set more off

***********************************************************************************************************************
* THIS ROUTINE GENERATES FIGURE A.VII OF WASEEM (2020) ROLE OF WITHHOLDING ...
***********************************************************************************************************************

/* IMPORTERS */

use					"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep              if business_sts=="2"
merge					m:1 regno using "$project_data\Master Short Updated Nov 2011.dta", keepusing(date_comm)
drop					if _merge==2
bys					regno:egen entry=min(taxperiod)
g						entrymonth=mofd(taxperiod)
g						regmonth=mofd(date_comm)
g						regmt6m=entrymonth>regmonth+6
keep					regno entry taxperiod fy item_cd business_sts tot_sale tot_purch regmt6m 
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
g 						period=mofd(entry)
qui					sum period
replace				period=period-r(min)+1
duplicates 			drop regno, force
bys					period:egen prop_regmt6m=mean(regmt6m)
replace				prop_regmt6m=prop_regmt6m*100
bys					period:g index=_n
#d;
twoway  				(line  prop_regmt6m period if period >24 & period<=108 & index==1,sort lwidth(thick) lcolor(red) mcolor(red) msymbol(O)),
						xtitle("Entry Period") xscale(titlegap(*10))
						xlabel(25 "1998" 37 "1999" 49 "2000" 61 "2001" 73 "2002" 85 "2003" 97 "2004" 109 "2005")
						xline(37 49, lpatter(dash) lcolor(green)) ytitle(Proportion Registered At Least Six Months Ago (%), alignment(bottom)) 
						ylabel(0(20)100)  yscale(titlegap(*10))
						graphregion(fcolor(white) style(none) color(white) margin(0 2 0 2)) bgcolor(white); 	
graph 				export "$project_output\ProportionRegistered_By_Entry_Importers.eps", replace;
#d						cr

/* DISTRIBUTORS, WHOLESALERS, & RETAILERS */

use					"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep              if business_sts=="4" | business_sts=="5" | business_sts=="6"
merge					m:1 regno using "$project_data\Master Short Updated Nov 2011.dta", keepusing(date_comm)
drop					if _merge==2
bys					regno:egen entry=min(taxperiod)
g						entrymonth=mofd(taxperiod)
g						regmonth=mofd(date_comm)
g						regmt6m=entrymonth>regmonth+6
keep					regno entry taxperiod fy item_cd business_sts tot_sale tot_purch regmt6m 
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
g 						period=mofd(entry)
qui					sum period
replace				period=period-r(min)+1
duplicates 			drop regno, force
bys					period:egen prop_regmt6m=mean(regmt6m)
replace				prop_regmt6m=prop_regmt6m*100
bys					period:g index=_n
#d;
twoway  				(line  prop_regmt6m period if period >24 & period<=108 & index==1,sort lwidth(thick) lcolor(red) mcolor(red) msymbol(O)),
						xtitle("Entry Period") xscale(titlegap(*10))
						xlabel(25 "1998" 37 "1999" 49 "2000" 61 "2001" 73 "2002" 85 "2003" 97 "2004" 109 "2005")
						xline(37 49, lpatter(dash) lcolor(green)) ytitle(Proportion Registered At Least Six Months Ago (%), alignment(bottom)) 
						ylabel(0(20)100)  yscale(titlegap(*10))
						graphregion(fcolor(white) style(none) color(white) margin(0 2 0 2)) bgcolor(white); 	
graph 				export "$project_output\ProportionRegistered_By_Entry_MS.eps", replace;
#d						cr

/* ENERGY SECTOR */

use					"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
g						ind=real(substr(item_cd,1,4))
g						es=0
replace				es=1 if ind>=2700 & ind<2800 
replace				es=0 if ind==2701 | ind==2714
keep              if es==1
merge					m:1 regno using "$project_data\Master Short Updated Nov 2011.dta", keepusing(date_comm)
drop					if _merge==2
bys					regno:egen entry=min(taxperiod)
g						entrymonth=mofd(taxperiod)
g						regmonth=mofd(date_comm)
g						regmt6m=entrymonth>regmonth+6
keep					regno entry taxperiod fy item_cd business_sts tot_sale tot_purch regmt6m 
g 						period=mofd(entry)
qui					sum period
replace				period=period-r(min)+1
duplicates 			drop regno, force
bys					period:egen prop_regmt6m=mean(regmt6m)
replace				prop_regmt6m=prop_regmt6m*100
bys					period:g index=_n
#d;
twoway  				(line  prop_regmt6m period if period >24 & period<=108 & index==1,sort lwidth(thick) lcolor(red) mcolor(red) msymbol(O)),
						xtitle("Entry Period") xscale(titlegap(*10))
						xlabel(25 "1998" 37 "1999" 49 "2000" 61 "2001" 73 "2002" 85 "2003" 97 "2004" 109 "2005")
						xline(37 49, lpatter(dash) lcolor(green)) ytitle(Proportion Registered At Least Six Months Ago (%), alignment(bottom)) 
						ylabel(0(20)100)  yscale(titlegap(*10))
						graphregion(fcolor(white) style(none) color(white) margin(0 2 0 2)) bgcolor(white); 	
graph 				export "$project_output\ProportionRegistered_By_Entry_ES.eps", replace;
#d						cr

/* SERVICES */

use					"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep              if business_sts=="8" 
merge					m:1 regno using "$project_data\Master Short Updated Nov 2011.dta", keepusing(date_comm)
drop					if _merge==2
bys					regno:egen entry=min(taxperiod)
g						entrymonth=mofd(taxperiod)
g						regmonth=mofd(date_comm)
g						regmt6m=entrymonth>regmonth+6
keep					regno entry taxperiod fy item_cd business_sts tot_sale tot_purch regmt6m 
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
g 						period=mofd(entry)
qui					sum period
replace				period=period-r(min)+1
duplicates 			drop regno, force
bys					period:egen prop_regmt6m=mean(regmt6m)
replace				prop_regmt6m=prop_regmt6m*100
bys					period:g index=_n
#d;
twoway  				(line  prop_regmt6m period if period >24 & period<=108 & index==1,sort lwidth(thick) lcolor(red) mcolor(red) msymbol(O)),
						xtitle("Entry Period") xscale(titlegap(*10))
						xlabel(25 "1998" 37 "1999" 49 "2000" 61 "2001" 73 "2002" 85 "2003" 97 "2004" 109 "2005")
						xline(37 49, lpatter(dash) lcolor(green)) ytitle(Proportion Registered At Least Six Months Ago (%), alignment(bottom)) 
						ylabel(0(20)100)  yscale(titlegap(*10))
						graphregion(fcolor(white) style(none) color(white) margin(0 2 0 2)) bgcolor(white); 	
graph 				export "$project_output\ProportionRegistered_By_Entry_Services.eps", replace;
#d						cr